package com.ruoyi.ommpuser.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ommpuser.domain.OmMpuser;
import com.ruoyi.ommpuser.service.IOmMpuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 问诊用户Controller
 * 
 * @author ningyi
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/om/mpuser")
public class OmMpuserController extends BaseController
{
    @Autowired
    private IOmMpuserService omMpuserService;

    /**
     * 查询问诊用户列表
     */
    @PreAuthorize("@ss.hasPermi('om:mpuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmMpuser omMpuser)
    {
        startPage();
        List<OmMpuser> list = omMpuserService.selectOmMpuserList(omMpuser);
        return getDataTable(list);
    }

    /**
     * 导出问诊用户列表
     */
    @PreAuthorize("@ss.hasPermi('om:mpuser:export')")
    @Log(title = "问诊用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmMpuser omMpuser)
    {
        List<OmMpuser> list = omMpuserService.selectOmMpuserList(omMpuser);
        ExcelUtil<OmMpuser> util = new ExcelUtil<OmMpuser>(OmMpuser.class);
        util.exportExcel(response, list, "问诊用户数据");
    }

    /**
     * 获取问诊用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('om:mpuser:query')")
    @GetMapping(value = "/{mpuserId}")
    public AjaxResult getInfo(@PathVariable("mpuserId") Long mpuserId)
    {
        return success(omMpuserService.selectOmMpuserByMpuserId(mpuserId));
    }

    /**
     * 新增问诊用户
     */
    @PreAuthorize("@ss.hasPermi('om:mpuser:add')")
    @Log(title = "问诊用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmMpuser omMpuser)
    {
        logger.info("om:mpuser:add -- {}",JSON.toJSONString(omMpuser));
        return toAjax(omMpuserService.insertOmMpuser(omMpuser));
    }

    /**
     * 修改问诊用户
     */
    @PreAuthorize("@ss.hasPermi('om:mpuser:edit')")
    @Log(title = "问诊用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmMpuser omMpuser)
    {
        return toAjax(omMpuserService.updateOmMpuser(omMpuser));
    }

    /**
     * 删除问诊用户
     */
    @PreAuthorize("@ss.hasPermi('om:mpuser:remove')")
    @Log(title = "问诊用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mpuserIds}")
    public AjaxResult remove(@PathVariable Long[] mpuserIds)
    {
        return toAjax(omMpuserService.deleteOmMpuserByMpuserIds(mpuserIds));
    }


}
